	var ilimit = null;
	var mylimit = null;
	var zuidayeshu = null;
	var keyword = null;
	var shenfen = null;
	//通过下拉事件触发ajax  请求每页显示数据条数
	$('select[name="sel"]').change(function(){
		mylimit = $(this).val();
		ilimit=1;
		keyword = $("input[name='keyword']").val();
		myajax(mylimit,ilimit,keyword);
		
	});
	//给页数显示绑定ajax 请求显示的页数
	$("#limit a").live('click',function(){
		mylimit = $('select[name="sel"]').val();
		ilimit = $(this).html();
		keyword = $("input[name='keyword']").val();
		if($(this).attr('class')=='paginate_button'){
			myajax(mylimit,ilimit,keyword);
		}
	});
	//给上一页绑定点击事件,  请求上一页数据
	$("#DataTables_Table_1_previous").click(function(){
		mylimit = $('select[name="sel"]').val();
		ilimit = parseInt($("#limit a[class='paginate_active']").html())-1;
		keyword = $("input[name='keyword']").val();
		if(ilimit<1){
			return false;
		}
		myajax(mylimit,ilimit,keyword);
	});
	//给第一页绑定点击事件,请求第一页数据
	$("#DataTables_Table_1_first").click(function(){
		mylimit = $('select[name="sel"]').val();
		ilimit = 1;
		keyword = $("input[name='keyword']").val();
		if($(this).attr('class')=='first paginate_button paginate_button_disabled'){
			return false;
		}
		myajax(mylimit,ilimit,keyword);
	});
	//给下一页绑定点击事件请求下一页数据
	$("#DataTables_Table_1_next").click(function(){
		mylimit = $('select[name="sel"]').val();
		ilimit = parseInt($("#limit a[class='paginate_active']").html())+1;
		keyword = $("input[name='keyword']").val();
		zuidayeshu = parseInt($("#limit a").last().html());
		if(ilimit>zuidayeshu){
			return false;
		}
		myajax(mylimit,ilimit,keyword);
		
	});
	$("#DataTables_Table_1_last").click(function(){
		mylimit = $('select[name="sel"]').val();
		ilimit = parseInt($('#limit span span').html());
		keyword = $("input[name='keyword']").val();
		if($(this).attr('class')=='previous paginate_button paginate_button_disabled'){
			return false;
		}
		myajax(mylimit,ilimit,keyword);
	});

	$("input[name=keyword]").keyup(function(ent){
		mylimit = $('select[name="sel"]').val();
		ilimit=1;
		keyword=$(this).val();
		myajax(mylimit,ilimit,keyword);
	});

	/*
	*	分页搜索请求使用的ajax
	*	mylimit  每页显示条数
	*	ilimit   显示第几页
	*/
	myajax(10,1,'')
	function myajax(mylimit,ilimit,keyword){
		if(!(ilimit>1)){
    // alert(ilimit);
        // ilimit = ilimit;
        ilimit=1;
    }
			$('#con').find('tr').remove();
			$.ajax({
				url:'/admin/user/user/limit',
				data:{'mylimit':mylimit,'ilimit':ilimit,'keyword':keyword},
				type:'get',
				dataType:'json',
				async:false,
				success:function(mes){
					$("#limit").find('a').remove();
					$("#limit a").attr('class','paginate_button');
					$("#limit a:eq("+(ilimit-1)+")").attr('class','paginate_active');
					var num = $(mes).length-1;
					if(parseInt(mes[num])>3){
						if(parseInt(ilimit)<3){
	    					var kaishi = 1;
	    					var jieshu = 3;
	    				}else{
	    					kaishi = parseInt(ilimit)-1;
	    					jieshu = parseInt(ilimit)+1;
	    				}
	    				if(parseInt(ilimit)==mes[num]){
	    					kaishi = parseInt(mes[num])-2;
	    					jieshu = parseInt(mes[num]);
	    				}
					}else{
						kaishi = 1;
						jieshu = parseInt(mes[num]);
					}
					var id = document.getElementById('limit');
					for(var i=kaishi;i<=jieshu;i++){
						var a = document.createElement('a');
						a.setAttribute('tabindex','0');
						a.setAttribute('class','paginate_button');
						if(i==ilimit){
							a.setAttribute('class','paginate_active');
						}
						a.innerHTML=i;
						id.appendChild(a);
					}
					$("#limit span").remove();
					var span = document.createElement('span');
						span.innerHTML='共<span>'+parseInt(mes[num])+'</span>页';
						id.appendChild(span);
					var status = null;
					$(mes).each(function(i){
						if((num)==i){
							return true;
						}
						if($(mes)[i].status==1){
							status='已激活';
						}else{
							status='未激活';
						}
						if($(mes)[i].auto==1){
							shenfen = '前台用户';
						}else if($(mes)[i].auto==2){
							shenfen = '一级管理员';
						}else if($(mes)[i].auto==3){
							shenfen = '二级管理员';
						}else{
							shenfen = '超级管理员';
						}
						if(i%2==0){
							var tr = $('<tr class="odd"><td class=" ">'+$(mes)[i].id+'</td><td class="sorting_1">'+$(mes)[i].username+'</td><td class="hidden-480 ">'+status+'</td><td class="hidden-480 ">'+shenfen+'</td><td class="hidden-480 "><a info="del" href="">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a info="xiugai" href="">修改</a></td></tr>');
						}else{
							var tr = $('<tr class="even"><td class=" ">'+$(mes)[i].id+'</td><td class="sorting_1">'+$(mes)[i].username+'</td><td class="hidden-480 ">'+status+'</td><td class="hidden-480 ">'+shenfen+'</td><td class="hidden-480 "><a info="del" href="">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a info="xiugai" href="">修改</a></td></tr>');
						}
						$("#con").append(tr);
					});
					

					if(ilimit!=1){
	        			$("#DataTables_Table_1_first").attr('class','first paginate_button');
	        			$("#DataTables_Table_1_previous").attr('class','previous paginate_button ');
	        		}else{
	        			$("#DataTables_Table_1_first").attr('class','first paginate_button paginate_button_disabled');
	        			$("#DataTables_Table_1_previous").attr('class','previous paginate_button paginate_button_disabled ');
	        		}			                		
	        		if(ilimit>=mes[num]){
	        			$("#DataTables_Table_1_next").attr('class','first paginate_button paginate_button_disabled');
	            		$("#DataTables_Table_1_last").attr('class','previous paginate_button paginate_button_disabled');
	        		}else{
	        			$("#DataTables_Table_1_next").attr('class','first paginate_button');
	            		$("#DataTables_Table_1_last").attr('class','previous paginate_button ');
	        		}

				}
			});
		}

//------------------------------------修改权限--------------------------------------------
	$('a[info="xiugai"]').live('click',function(){
		$('#lvjing').css('display','block');
		$('#biaodan').css('display','block');
		// console.log($(this).parent().prevAll().eq('2').html());
		$('input[name="user"]').val($(this).parent().prevAll().eq('2').html());
		$('input[name="id"]').val($(this).parent().prevAll().eq('3').html());
		var shenfen = $(this).parent().prevAll().eq('0').html()
		if(shenfen=='超级管理员'){
			$('select[name=auto]').val(4);
		}else if(shenfen=='二级管理员'){
			$('select[name=auto]').val(3);
		}else if(shenfen=='一级管理员'){
			$('select[name=auto]').val(2);
		}else{
			$('select[name=auto]').val(1);
		}
		return false;
	});
	$('#tijiao').click(function(){
		var id = $('input[name="id"]').val();
		var auto = $('select[name="auto"]').val();
		$('#biaodan').css('display','none');
		$.ajax({
			url:'/admin/user/user/edit',
			data:{'id':id,'auto':auto},
			type:'post',
			// dataType:'json',
			success:function(mes){
				if(mes=='yes'){
					mylimit = $('select[name="sel"]').val();
					ilimit = parseInt($("#limit a[class='paginate_active']").html());
					keyword = $("input[name='keyword']").val();
					myajax(mylimit,ilimit,keyword);
					$("#tishi").css('display','block');
					$("#tishi").html('<span style="color:green">修改成功,1秒后自动关闭</span>');
					setTimeout(function(){
						$('#lvjing').css('display','none');
						$("#tishi").css('display','none');
					},1000);

				}else{
					$("#tishi").css('display','block');
					$("#tishi").html('<span style="color:red;">修改失败,1秒后自动关闭</span>');
					setTimeout(function(){
						$('#lvjing').css('display','none');
						$("#tishi").css('display','none');
					},1000);
				}
			}
		});
		return false;
	});

//----------------------------------------------------删除----------------------------------------------
$('a[info="del"]').live('click',function(){
	var id = $(this).parent().prevAll().eq('3').html();
	$.ajax({
		url:'/admin/user/user/del',
		data:{'id':id},
		type:'get',
		success:function(mes){
			if(mes=='yes'){
				mylimit = $('select[name="sel"]').val();
				ilimit = parseInt($("#limit a[class='paginate_active']").html());
				keyword = $("input[name='keyword']").val();
				myajax(mylimit,ilimit,keyword);
				$("#tishi").css('display','block');
				$('#lvjing').css('display','block');
				$("#tishi").html('<span style="color:green">删除成功,1秒后自动关闭</span>');
				setTimeout(function(){
					$('#lvjing').css('display','none');
					$("#tishi").css('display','none');
				},1000);
			}else{
				$("#tishi").css('display','block');
				$('#lvjing').css('display','block');
				$("#tishi").html('<span style="color:green">删除失败,1秒后自动关闭</span>');
				setTimeout(function(){
					$('#lvjing').css('display','none');
					$("#tishi").css('display','none');
				},1000);
			}
			
		}
	});
	return false;
});

//-------------------------------------------------------添加用户----------------------------------------------------
	$('.add').click(function(){
		$('#lvjing').css('display','block');
		$('.tianjia').css('display','block');
	});
	
	var yzzhanghao = null;
	$('#tianjia').click(function(){
		if(yzzhanghao){
			return false;
		}
		var username = $('input[name="username"]').val();
		var password = $('input[name="password"]').val();
		var repassword = $('input[name="repassword"]').val();
		var auto = $('select[name="auto1"]').val();
		// console.log(username+'---'+password+'---'+repassword+'----'+auto);
		$('.tianjia').css('display','none');
		
		$.ajax({
			url:'/admin/user/user/insert',
			data:{'username':username,'password':password,'repassword':repassword,'auto':auto,'fenghao':'0','huishou':'0','status':'0'},
			type:'post',
			success:function(mes){
				if(mes=='yes'){
					mylimit = $('select[name="sel"]').val();
					ilimit = parseInt($("#limit a[class='paginate_active']").html());
					keyword = $("input[name='keyword']").val();
					myajax(mylimit,ilimit,keyword);
					$("#tishi").css('display','block');
					$('#lvjing').css('display','block');
					$("#tishi").html('<span style="color:green">添加成功,1秒后自动关闭</span>');
					setTimeout(function(){
						$('#lvjing').css('display','none');
						$("#tishi").css('display','none');
					},1000);
				}else{
					$("#tishi").css('display','block');
					$('#lvjing').css('display','block');
					$("#tishi").html('<span style="color:green">添加失败,1秒后自动关闭</span>');
					setTimeout(function(){
						$('#lvjing').css('display','none');
						$("#tishi").css('display','none');
					},1000);
				}
				// $('input[name="username"]').val('');
				// $('input[name="password"]').val('');
				// $('input[name="repassword"]').val('');
				// $('select[name="auto1"]').val(1);
				$("input[name='res']").click();
			}
		});
		return false;
	});
	$('input[name="username"]').focusout(function(){
		var username = $(this).val();
		if(username==''){
			$('span[info="zhanghaotishi1"]').css('display','none');
			$('span[info="zhanghaotishi2"]').css('display','none');
			$('span[info="zhanghaotishi3"]').css('display','block');
			return false;
		}
		$.ajax({
			url:"/admin/user/user/sel",
			data:{'username':username},
			type:'post',
			success:function(mes){
				if(mes=='yes'){
					yzzhanghao = false;
					$('span[info="zhanghaotishi1"]').css('display','none');
					$('span[info="zhanghaotishi3"]').css('display','none');
					$('span[info="zhanghaotishi2"]').css('display','block');

				}else{
					$('span[info="zhanghaotishi3"]').css('display','none');
					$('span[info="zhanghaotishi2"]').css('display','none');
					$('span[info="zhanghaotishi1"]').css('display','block');
					yzzhanghao = true;
				}		
			}
		});
	});
	$("input[name='res']").click(function(){
		$('span[info="zhanghaotishi1"]').css('display','none');
		$('span[info="zhanghaotishi2"]').css('display','none');
		$('span[info="zhanghaotishi3"]').css('display','none');
	});